package com.codinghero.zqlb.weibo.sina.dao;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import com.codinghero.zqlb.spider.dao.BaseDao;
import com.codinghero.zqlb.weibo.sina.dto.Weibo;

public class WeiboDao extends BaseDao {

	public int insertWeibo(Weibo weibo) throws SQLException {
		return dbOper.insertOne(weibo);
	}
	
	public Weibo getValidWeiboByDateAndSeq(int curDateInt, int seq) throws SQLException {
		String sql = "SELECT * FROM zqlb_weibo WHERE curDate = " + curDateInt + " and seq=" + seq + " and status=1";
		return dbOper.selectOne(sql, Weibo.class);
	}
	
	public List<Weibo> getAllWeiboByDateRange(int startDateInt, int endDateInt) throws SQLException {
		String sql = "SELECT * FROM zqlb_weibo WHERE curDate >= "
				+ startDateInt + " AND curDate<= " + endDateInt + "";
		return dbOper.selectList(sql, Weibo.class);
	}
	
	public void deleteWeiboByDateAndSeq(int curDateInt, int seq) throws SQLException {
		String sql = "DELETE FROM zqlb_weibo WHERE curDate = " + curDateInt + " and seq=" + seq;
		dbOper.executeUpdate(sql);
	}

	public static void main(String[] args) {
		Weibo weibo = new Weibo();
		weibo.setDes("test");
		weibo.setCurDate(new Date());

		WeiboDao dao = new WeiboDao();
		try {
			dao.connect();
			dao.insertWeibo(weibo);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dao.close();
		}
	}
}
